#!/usr/bin/perl

######################################################################
package Swignition::uF::xoxo;
######################################################################

use XML::LibXML qw(:all);
use XML::XOXO;
use strict;


sub parse_all
{
	my $page   = shift;
	my $within = shift || $page->{DOM};
	my @rv;
	
	my @nodes = Swignition::GenericParser::Utils::searchClass('xoxo', $within);
	foreach my $l (@nodes)
	{
		my $l_parsed = parse($page, $l);
		push @rv, $l_parsed;
	}
	
	return @rv;
} #/sub parse_all


sub uri
{
	my $this = shift;
	my $all  = shift;
	my @rv;
	
	if (length $this->{_id})
	{
		push @rv, $this->{_page}->uri.'#'.$this->{_id};
	}
	if (lc($this->{_dom}->tagName) eq 'body')
	{
		push @rv, $this->{_page}->uri;
	}
	push @rv, Swignition::GenericParser::Utils::BNodeURI($this->{_dom}, 'List')
		unless (@rv);
	
	return $rv[0] unless (defined $all);
	while ($all) { shift @rv; $all--; }
	return @rv;
}


sub parse
{
	my $page = shift;
	my $rv = { '_dom'=>shift };
	my $pkg = __PACKAGE__;
	if (defined $page->{uF}->{_Shortcuts}->{$pkg}->{ $rv->{_dom}->getAttribute('_xpath') })
		{ return $page->{uF}->{_Shortcuts}->{$pkg}->{ $rv->{_dom}->getAttribute('_xpath') }; }
	else
		{ $page->{uF}->{_Shortcuts}->{$pkg}->{ $rv->{_dom}->getAttribute('_xpath') } = $rv; }
	
	my $list_node = $rv->{'_dom'}->cloneNode(1);

	my $id = $list_node->getAttribute('id');
	$rv->{_id} = $id if (length $id);
	$rv->{_page} = $page;
	
	my $parser = XML::XOXO::Parser->new();
	$rv->{'object'} = $parser->parse($list_node->toString);
	
	bless $rv;
	return $rv;
	
} #/sub parse


1; #/package Swignition::uF::xoxo




